﻿<template>
    <el-dialog
        title="重新分配供应商"
        v-model="visible"
        :width="1400"
        destroy-on-close
        :close-on-click-modal="false"
        :before-close="handleBeforeClose"
    >
        <el-form
            :model="entityObj"
            :rules="rules"
            :disabled="mode == 'Show'"
            ref="dialogForm"
            label-width="100px"
        >
            <el-steps
                :active="2"
                align-center
                finish-status="success"
                style="margin-top: -20px;margin-bottom: 18px;"
            >
                <el-step title="门店已下单" description />
                <el-step title="重新分配供应商" description />
                <el-step title="已完成" description />
            </el-steps>
            <el-collapse v-model="activeNames">
                <el-collapse-item title="基础信息" name="1">
                    <el-row>
                        <el-col :span="8">
                            <el-form-item
                                label-width="120px"
                                label="要货编号:"
                            >{{entityObj.applyOrderCode}}</el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label-width="120px" label="要货时间:">{{entityObj.applyDate}}</el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label-width="120px"
                                label="期望到货时间:"
                            >{{entityObj.expectedDate}}</el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-form-item label-width="120px" label="要货单位:">
                                <el-tooltip placement="top">
                                    <template #content>
                                        联系人: {{entityObj.realName}}
                                        <br />
                                        联系电话:{{entityObj.mobile}}
                                        <br />
                                        收货地址:{{entityObj.address}}
                                    </template>
                                    <span style="color: blue;">{{entityObj.storeName}}</span>
                                </el-tooltip>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label-width="120px" label="供货单位:">
                                <el-tooltip placement="top">
                                    <template #content>
                                        联系人: {{entityObj.purchaseRealName}}
                                        <br />
                                        联系电话:{{entityObj.purchaseMobile}}
                                        <br />
                                        联系地址:{{entityObj.purchaseAddress}}
                                    </template>
                                    <span style="color: blue;">{{entityObj.purchaseUnityName}}</span>
                                </el-tooltip>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label-width="120px" label="申请人:">{{entityObj.applyName}}</el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-form-item label-width="120px" label="申请时间:">{{entityObj.applyDate}}</el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label-width="120px"
                                label="最后修改人:"
                            >{{entityObj.updateName}}</el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item
                                label-width="120px"
                                label="最后修改时间:"
                            >{{entityObj.updateTime}}</el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-form-item
                                label-width="120px"
                                label="附件:"
                                v-if="entityObj.applyFile"
                            >
                                <sc-upload-file
                                    v-model="entityObj.applyFile"
                                    :objName="'Supply/ApplyOrder'"
                                    draggable
                                    :uploadType="'OSS'"
                                    :bucketName="'jtmc'"
                                    disabled
                                    :limit="1"
                                />
                            </el-form-item>
                            <el-form-item label-width="120px" label="附件:" v-else>无</el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="8">
                            <el-form-item label-width="120px" label="备注:">{{entityObj.remarks}}</el-form-item>
                        </el-col>
                    </el-row>
                </el-collapse-item>
                <el-collapse-item title="要货清单" name="2">
                    <!-- 要货清单 -->
                    <el-row>
                        <el-col :span="24">
                            <el-table
                                :data="entityObj.applyOrderItems"
                                :border="true"
                                style="width: 100%"
                                default-expand-all
                                :row-class-name="tableRowClassName"
                            >
                                <!-- <el-table-column type="expand">
                                    <template #default="props">
                                        <el-table
                                            :data="props.row.purchases"
                                            :border="true"
                                            :row-class-name="tableRowClassName1"
                                        >
                                            <el-table-column label="供应商" width="280">
                                                <template #default="scope">
                                                    <el-select
                                                        placeholder="---供应商---"
                                                        v-model="scope.row.supplierId"
                                                        style="width: 100%"
                                                    >
                                                        <el-option
                                                            v-for="item in scope.row.suppliers"
                                                            :key="item.orgId"
                                                            :label="item.orgName"
                                                            :value="item.orgId"
                                                        />
                                                    </el-select>
                                                </template>
                                            </el-table-column>
                                            <el-table-column label="采购模式" width="140">
                                                <template #default="scope">
                                                    <el-select
                                                        placeholder="---采购模式---"
                                                        v-model="scope.row.purchaseSaleType"
                                                        style="width: 100%"
                                                    >
                                                        <el-option
                                                            v-for="item in scope.row.suppliers.find(p=>p.orgId==scope.row.supplierId)?.purchaseSaleItems"
                                                            :key="item.purchaseSaleType"
                                                            :label="item.purchaseSaleTypeDesc"
                                                            :value="item.purchaseSaleType"
                                                        />
                                                    </el-select>
                                                </template>
                                            </el-table-column>
                                            <el-table-column label="本次采购量" width="280">
                                                <template #default="scope">
                                                    <el-input-number
                                                        v-model="scope.row.qty"
                                                        :precision="0"
                                                        :step="1"
                                                        :disabled="false"
                                                        style="width: 100%"
                                                        @change="handleQuantityChange(scope.row,props.row)"
                                                    />
                                                </template>
                                            </el-table-column>
                                            <el-table-column label="采购单价" width="90" prop="price">
                                                <template
                                                    #default="scope"
                                                >{{scope.row.price=scope.row.suppliers.find(p=>p.orgId==scope.row.supplierId)?.price??0}}</template>
                                            </el-table-column>
                                            <el-table-column label="采购金额" width="90">
                                                <template
                                                    #default="scope"
                                                >{{scope.row.qty*scope.row.price}}</template>
                                            </el-table-column>
                                            <el-table-column label="库存" width="90">
                                                <template
                                                    #default="scope"
                                                >{{scope.row.suppliers.find(p=>p.orgId==scope.row.supplierId)?.purchaseSaleItems?.find(p=>p.purchaseSaleType==scope.row.purchaseSaleType)?.stockQty}}</template>
                                            </el-table-column>
                                            <el-table-column label="备注">
                                                <template #default="scope">
                                                    <el-input
                                                        v-model="scope.row.remarks"
                                                        style="width: 100%"
                                                    />
                                                </template>
                                            </el-table-column>
                                            <el-table-column label="操作" width="90">
                                                <template #default="scope">
                                                    <el-button
                                                        size="small"
                                                        v-if="scope.$index>=1"
                                                        @click="deleteRow(props.row,scope.$index)"
                                                    >删除</el-button>
                                                </template>
                                            </el-table-column>
                                        </el-table>
                                    </template>
                                </el-table-column>-->
                                <el-table-column label="物料编码" prop="materialCode" width="120" />
                                <el-table-column label="物料名称" prop="materialName" width="200">
                                    <template #default="scope">
                                        <div
                                            v-if="scope.row.materialImages && scope.row.materialImages.length > 0"
                                            style="color: #318cf2;"
                                            @click="handlePreview(scope.row)" 
                                        >{{scope.row.materialName}}</div>
                                        <div v-else>{{scope.row.materialName}}</div>
                                    </template>
                                </el-table-column>
                                <el-table-column label="规格" prop="materialSpecs" width="120" />
                                <el-table-column label="单位" prop="unitName" width="60" />
                                <!-- <el-table-column label="分类" prop="materialTypeName" width="120" /> -->

                                <el-table-column label="要货数量" prop="qty" width="90" />
                                <el-table-column label="销售单价" prop="price" width="90" />
                                <el-table-column label="金额" prop="totalAmount" width="90" />
                                <el-table-column label="供应商" prop="suppliers" width="150">
                                    <template #default="scope">
                                        <span style="color: #318cf2;">
                                            {{
                                            getSupplierDesc(scope.row.purchases,scope.row.purchases[0].suppliers)
                                            }}
                                        </span>
                                    </template>
                                </el-table-column>
                                <el-table-column label="备注" prop="remarks" />
                                <el-table-column label="操作" fixed="right" align="right" width="60">
                                    <template #default="scope">
                                        <el-button-group>
                                            <el-button
                                                text
                                                type="primary"
                                                size="small"
                                                @click="opReceive(scope.row, scope.$index)"
                                            >拆单</el-button>
                                        </el-button-group>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </el-col>
                    </el-row>
                </el-collapse-item>
            </el-collapse>

            <el-row style="margin-top: 10px;">
                <el-col :span="8">
                    <el-form-item label-width="120px" label="采购总数量:">{{totalQty}}</el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label-width="120px" label="采购总金额:">{{totalAmount}}</el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item label-width="120px" label="备注">
                        <el-input v-model="entityObj.remarks" type="textarea" :rows="2" />
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <template #footer>
            <el-button @click="handleBeforeClose">取 消</el-button>
            <!-- <el-button
                v-if="mode != 'show'"
                type="primary"
                :loading="isSaveing"
                @click="returned(1)"
            >退 回</el-button> -->
            <el-button
                v-if="mode != 'show'"
                type="primary"
                :loading="isSaveing"
                @click="submit(2)"
            >保 存</el-button>
        </template>

        <template>
            <el-dialog
                v-model="materialState"
                title="选择商品"
                :width="1000"
                :center="true"
                append-to-body
                style="height: 480px"
            >
                <el-row>
                    <sc-material-choice ref="scMaterialChoice" :queryType="'material/item-pages'"></sc-material-choice>
                </el-row>
                <template #footer>
                    <el-button @click="materialState = false">取 消</el-button>
                    <el-button type="primary" :loading="isSaveing" @click="setMaterialChoice">确定</el-button>
                </template>
            </el-dialog>
        </template>
    </el-dialog>
    <receive-detail-dialog
        v-if="receiveDetailSave"
        ref="receiveDetailDialog"
        @splitOrder="splitOrder"
        @saveOrder="saveOrder"
        @getSupplierDesc="getSupplierDesc"
        @closed="receiveDetailSave = false"
    ></receive-detail-dialog>

    <!-- 预览组件 -->
    <el-image-viewer v-if="showImage" @close="closeViewer" :hide-on-click-modal="true" :url-list="srcList" />
</template>



<script>
import tool from "@/utils/tool";
import receiveDetailDialog from "./receiveDetail";
export default {
    components: {
        receiveDetailDialog,
    },
    emits: ["success", "closed"],
    data() {
        return {
            activeNames: ["2", "3"],
            tableRowClassName: "warning-row",
            tableRowClassName1: "success-row",
            mode: "Add",
            //预览图片
            previewUrl: [],
            //预览图片列表
            srcList: [],
            showImage: false,
            titleMap: {
                Add: "c",
                Edit: "编辑",
                Show: "查看",
            },
            entityObj: {
                purchaseProtocolId: 0,
                purchaseProtocolCode: "",
                purchaseProtocolName: "",
                status: 1,
                crName: "",
                crDate: "",
                supplier: {},
                protocolDate: [],
                purchaseUnityName: "",
                remarks: "",
                protocolFile: "",
                purchaseProtocolItems: [],
                giveOrderItems: [],
            },
            receiveDetailSave: false,
            materialState: false,
            queryList: {},
            visible: false,
            isSaveing: false,
            needSaveFlag: false,
            //验证规则
            rules: {
                purchaseProtocolName: [
                    { required: true, type: "string", message: "请填写" },
                ],
                purchaseUnityName: [
                    { required: true, type: "string", message: "请填写" },
                ],
                supplier: [
                    { required: true, type: "object", message: "请填写" },
                ],
                protocolDate: [
                    { required: true, type: "array", message: "请填写" },
                ],
                crName: [{ required: true, type: "string", message: "请填写" }],
                crDate: [{ required: true, type: "string", message: "请填写" }],
                materialSpecs: [
                    { required: true, type: "string", message: "请填写" },
                ],
                purchaseProtocolItems: [
                    {
                        required: true,
                        type: "array",
                        message: "请填写",
                        trigger: "change",
                    },
                ],
            },
            props: {
                label: "supplierName",
                value: "supplierId",
            },
            materialProps: {
                label: "materialCode",
                value: "materialId",
                items: "materialItems",
            },
            materialTypeTree: [],
            optionsBrand: [],
            optionsUnit: [],
            optionsPurchaseSaleType: [],
            applySuppliers: [],
            giveSuppliers: [],
        };
    },
    computed: {
        totalQty() {
            let applyOrderItems = this.entityObj.applyOrderItems;
            let purchaseQty = 0;
            applyOrderItems?.map((element) => {
                element.purchases?.map((t) => (purchaseQty += t.qty));
            });
            return purchaseQty;
        },
        totalAmount() {
            let applyOrderItems = this.entityObj.applyOrderItems;
            let totalAmount = 0;
            applyOrderItems?.map((element) => {
                element.purchases?.map((t) => {
                    const price =
                        t.suppliers.find((z) => z.supplierId == t.supplierId)
                            ?.price ?? 0;
                    totalAmount += t.qty * price;
                });
            });
            return totalAmount;
        },
    },
    methods: {
        //图片预览
        handlePreview(row) {
            console.log("row", row.materialImages);
            if (!row.materialImages || row.materialImages.length == 0) {
                return;
            }
            this.previewUrl = row.materialImages[0]; // 设置当前预览的图片 URL
            this.srcList = row.materialImages; // 设置预览列表
            this.showImage = true; // 显示 el-image
        },
        closeViewer() {
            this.showImage = false;
        },
        handleBeforeClose() {
            this.$confirm("信息未保存,确定要关闭吗？", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    this.visible = false;
                })
                .catch(() => {
                    // 用户点击了取消按钮，不执行关闭
                });
        },
        //显示=
        open(mode = "Add") {
            this.mode = mode;
            this.visible = true;
            return this;
        },
        //表单提交方法
        submit(status) {
            this.$refs.dialogForm.validate(async (valid) => {
                if (valid) {
                    let data = {
                        refundPurchaseOrderId:
                            this.entityObj.refundPurchaseOrderId,
                        applyOrderId: this.entityObj.applyOrderId,
                        remarks: this.entityObj.remarks,
                        status: status,
                        applyOrderItems: [],
                        giveOrderItems: this.entityObj.giveOrderItems,
                    };

                    this.entityObj.applyOrderItems.map((p) => {
                        p.purchases.map((t) => {
                            data.applyOrderItems.push({
                                applyOrderItemId: p.applyOrderItemId,
                                materialTypeId: p.materialTypeId,
                                purchaseSaleType: t.purchaseSaleType,
                                materialId: p.materialId,
                                materialItemId: p.materialItemId,
                                qty: t.qty,
                                supplierOrgType:t.supplierOrgType,
                                supplierId: t.supplierId,
                                remarks: t.remarks,
                            });
                        });
                    });

                    try {
                        var returnValue =
                            await this.$API.auth.PostProcessApi.post(
                                "purchase-order/create",
                                { ...data }
                            );
                        if (returnValue.status == 200) {
                            this.$message.success("操作成功");
                            this.$emit("fatherMethod");
                            this.isSaveing = false;
                            this.visible = false;
                        } else {
                            this.$message.error("操作失败:" + returnValue.msg);
                            this.isSaveing = false;
                        }
                    } catch (error) {
                        this.loading = false;
                        this.isSaveing = false;
                        return false;
                    }
                }
            });
        },
        //退回
        returned() {
            this.$refs.dialogForm.validate(async (valid) => {
                if (valid) {
                    let data = {
                        applyOrderIds: [this.entityObj.applyOrderId],
                        remarks: this.entityObj.remarks,
                    };

                    try {
                        var returnValue =
                            await this.$API.auth.PostProcessApi.post(
                                "apply-order/returned",
                                { ...data }
                            );
                        if (returnValue.status == 200) {
                            this.$message.success("操作成功");
                            this.$emit("fatherMethod");
                            this.isSaveing = false;
                            this.visible = false;
                        } else {
                            this.$message.error("操作失败:" + returnValue.msg);
                            this.isSaveing = false;
                        }
                    } catch (error) {
                        this.loading = false;
                        this.isSaveing = false;
                        return false;
                    }
                }
            });
        },
        //表单注入数据
        async setData(data) {
            this.entityObj = {};
            console.log("重新分配供应商", data);
            const returnData = await this.$API.auth.GetProcessApi.get(
                "refund-purchase-order/apply-order/" +
                    data.refundPurchaseOrderId,
                {}
            );
            if (returnData.status == 200) {
                let applyOrderItems =
                    returnData.response.applyOrderItems.filter(
                        (p) =>
                            p.purchaseSaleType == 0 ||
                            p.purchaseSaleType == 1 ||
                            p.purchaseSaleType == 4 ||
                            p.purchaseSaleType == 5 ||
                            p.purchaseSaleType >= 20
                    );
                console.log("applyOrderItems", applyOrderItems);
                if (applyOrderItems.length > 0) {
                    await this.setSplitItems(applyOrderItems, data.storeId, 0);
                }

                let giveOrderItems = returnData.response.applyOrderItems.filter(
                    (p) => p.purchaseSaleType == 2 || p.purchaseSaleType == 3
                );
                if (giveOrderItems.length > 0) {
                    await this.setSplitItems(giveOrderItems, data.storeId, 1);
                }
                this.entityObj = {
                    ...returnData.response,
                    refundPurchaseOrderId: data.refundPurchaseOrderId,
                };
            }

            this.activeNames = ["2", "3"];
        },
        async setSplitItems(items, storeId, type) {
            const materialItemIds = items.map((p) => p.materialItemId);
            const returnValue = await this.$API.auth.PostProcessApi.post(
                "purchase-protocol/orgs",
                {
                    materialItemIds: materialItemIds,
                    storeOrgType: items[0].storeOrgType,
                    storeId: items[0].storeId,
                    orderType: type,
                }
            );
            console.log("returnValue", returnValue);
            if (returnValue.status == 200) {
                if (type == 0) {
                    this.applySuppliers = returnValue.response;
                } else {
                    this.giveSuppliers = returnValue.response;
                }

                console.log("供应商", this.suppliers);
                const _this = this;
                items.map((p) => {
                    const suppliers =
                        type == 0
                            ? _this.applySuppliers.find(
                                  (t) => t.materialItemId == p.materialItemId
                              ).purchaseOrgs
                            : _this.giveSuppliers.find(
                                  (t) => t.materialItemId == p.materialItemId
                              ).purchaseOrgs;
                    p.purchases.map((t) => {
                        t.suppliers = suppliers;
                    });
                    if (p.purchases && p.purchases.length == 0) {
                        p.purchases.push({
                            suppliers: suppliers,
                            supplierOrgType:suppliers && suppliers.length > 0? suppliers[0].orgType: null,
                            supplierId:
                                suppliers && suppliers.length > 0
                                    ? suppliers[0].orgId
                                    : null,
                            qty: p.qty,
                            price:
                                suppliers && suppliers.length > 0
                                    ? suppliers[0].price
                                    : 0.0,
                            totalAmount:
                                p.qty *
                                (suppliers && suppliers.length > 0
                                    ? suppliers[0].price
                                    : 0.0),
                            optionsPurchaseSaleType:
                                suppliers && suppliers.length > 0
                                    ? suppliers[0].purchaseSaleItems
                                    : null,
                            purchaseSaleType:
                                suppliers && suppliers.length > 0
                                    ? suppliers[0].purchaseSaleItems[0]
                                          ?.purchaseSaleType
                                    : null,
                            stockQty:
                                suppliers && suppliers.length > 0
                                    ? suppliers[0].purchaseSaleItems[0]
                                          ?.stockQty
                                    : null,
                        });
                    }
                });
            }
        },
        //拆单
        async splitOrder(data) {
            console.log("split", data);
            const suppliers =
                data.purchaseSaleType == 2 || data.purchaseSaleType == 3
                    ? this.giveSuppliers.find(
                          (t) => t.materialItemId == data.materialItemId
                      ).purchaseOrgs
                    : this.applySuppliers.find(
                          (t) => t.materialItemId == data.materialItemId
                      ).purchaseOrgs;
            let totalQty = 0;
            data.purchases.map((p) => (totalQty += p.qty));
            data.purchases.push({
                suppliers: suppliers,
                supplierOrgType:suppliers && suppliers.length > 0? suppliers[0].orgType: null,
                supplierId:
                    suppliers && suppliers.length > 0
                        ? suppliers[0].orgId
                        : null,
                qty: data.qty - totalQty,
                price:
                    suppliers && suppliers.length > 0
                        ? suppliers[0].price
                        : 0.0,
                totalAmount:
                    (data.qty - totalQty) *
                    (suppliers && suppliers.length > 0
                        ? suppliers[0].price
                        : 0.0),
                optionsPurchaseSaleType:
                    suppliers && suppliers.length > 0
                        ? suppliers[0].purchaseSaleItems
                        : null,
                purchaseSaleType:
                    suppliers && suppliers.length > 0
                        ? suppliers[0].purchaseSaleItems[0]?.purchaseSaleType
                        : null,
                stockQty:
                    suppliers && suppliers.length > 0
                        ? suppliers[0].purchaseSaleItems[0]?.stockQty
                        : null,
            });
        },
        //接单
        opReceive(data) {
            this.receiveDetailSave = true;
            this.$nextTick(() => {
                this.$refs.receiveDetailDialog.setData(data);
                this.$refs.receiveDetailDialog.open("Add");
            });
        },
        async saveOrder(data) {
            console.log(data);
            this.entityObj.applyOrderItems.find(
                (p) => p.applyOrderItemId == data.applyOrderItemId
            ).purchases = [...data.purchases];
        },
        //获取供应商信息
        getSupplierDesc(purchases, suppliers) {
            if (purchases && suppliers) {
                const supplierTotals = suppliers.map((p) => {
                    let totalQty = 0;
                    purchases
                        .filter((t) => t.supplierId == p.orgId)
                        .map((z) => (totalQty += z.qty));
                    return {
                        name: p?.orgName,
                        totalQty: totalQty,
                    };
                });
                console.log(supplierTotals);
                //排序
                const sortedSupplierTotals = supplierTotals.sort(
                    (a, b) => b.totalQty - a.totalQty
                );
                return sortedSupplierTotals
                    .map((supplier) => `${supplier.name}/${supplier.totalQty}`)
                    .join(", ");
            }
        },
        handleQuantityChange(row, data) {
            let totalQty = 0;
            data.purchases.forEach((p) => (totalQty += p.qty));
            if (row.qty < 0) {
                this.$nextTick(() => {
                    row.qty = 0;
                });
                this.$message.error("采购数量不能小于0");
            }

            if (totalQty > data.qty) {
                this.$nextTick(() => {
                    row.qty -= totalQty - data.qty;
                });
                this.$message.error("采购数量不能大于要货数量");
            }
        },
        async initOptions() {
            try {
                var returnValue = await this.$API.auth.PostProcessApi.post(
                    "base-dictionary/options",
                    { Codes: ["PurchaseSaleType"] }
                );
                if (returnValue.status == 200) {
                    this.optionsPurchaseSaleType = returnValue.response.find(
                        (p) => p.code == "PurchaseSaleType"
                    ).optionsDetails;
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }
        },
        addMaterial() {
            this.materialState = true;
        },
        deleteRow(data, index) {
            data.purchases.splice(index, 1);
        },
        setMaterialChoice() {
            let materials = this.$refs.scMaterialChoice.selectionRows;

            materials.map((p) => {
                this.entityObj.giveOrderItems.push({
                    materialId: p.materialId,
                    materialCode: p.materialCode,
                    materialName: p.materialName,
                    materialSpecs: p.materialSpecs,
                    materialTypeId: p.materialTypeId,
                    materialTypeName: p.materialTypeName,
                    unitCode: p.unitCode,
                    unitName: p.unitName,
                    price: p.price,
                    remarks: "",
                    materialItemId: p.materialItemId,
                });
            });
            console.log(this.entityObj.giveOrderItems);
            this.materialState = false;
        },
        formatDate(date) {
            const year = date.getFullYear();
            const month = String(date.getMonth() + 1).padStart(2, "0");
            const day = String(date.getDate()).padStart(2, "0");
            const hours = String(date.getHours()).padStart(2, "0");
            const minutes = String(date.getMinutes()).padStart(2, "0");
            const seconds = String(date.getSeconds()).padStart(2, "0");

            return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
        },
    },
    async mounted() {
        this.entityObj.purchaseUnityName = tool.data.get("USER_INFO").OrgName;
        this.entityObj.crName = tool.data.get("USER_INFO").Name;
        this.entityObj.crDate = this.formatDate(new Date());
        await this.initOptions();
    },
};
</script>

<style scoped>
.el-table .warning-row {
    --el-table-tr-bg-color: var(--el-color-warning-light-9);
}
.el-table .success-row {
    --el-table-tr-bg-color: var(--el-color-success-light-9);
}
.el-form-item {
    margin-bottom: 8px !important;
}
</style>
